package com.wzy.vx.handler;

import com.wzy.vx.Utils.ResuletVoUtils;
import com.wzy.vx.VO.ResultVo;
import com.wzy.vx.exception.SellException;
import com.wzy.vx.exception.SellerAuthorizeException;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

/**
 * @ProjectName: vx
 * @Package: com.wzy.vx.handler
 * @ClassName: ExeceptionHandler
 * @Author: Administrator
 * @Description: ${description}
 * @Date: 2019/3/25 16:44
 * @Version: 1.0
 */
@ControllerAdvice
public class ExeceptionHandler {

    //拦截异常
    @ExceptionHandler(value = SellerAuthorizeException.class)
    @ResponseStatus(value= HttpStatus.FORBIDDEN)
    public ModelAndView handlerAuthorizeception(){
        return new ModelAndView("redirect:"
                .concat("http://wzy.natapp1.cc/")
                .concat("/sell/wechat/qrAuthorize")
                .concat("?returnUrl=")
                .concat("http://wzy.natapp1.cc/")
                .concat("/sell/seller/login"));
    }

    //拦截异常
    @ExceptionHandler(value = SellException.class)
    @ResponseBody
    public ResultVo handlerSellException(SellException e){
        return ResuletVoUtils.error(e.getCode(),e.getMessage());
    }

}
